package net.dodoman;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;

public class TestMain {
	public static void main(String[] args) {
		outObject();
		inputObject();
	}

	private TestMain() {

	}

	private static void forTest() {
		for (int i = 0; i < 2; i++) {
			System.out.println("outter");
			for (int j = 0; j < 2; j++) {
				System.out.println("inner");
				if (j == 2)
					break;
			}
			System.out.println("break1");
		}
		System.out.println("break2");
	}

	/**
	 * 对象序列化
	 */
	private static void outObject() {
		Date date = new Date();
		try {
			FileOutputStream fos = new FileOutputStream(new File("E:/abc.date"));
			ObjectOutputStream oos = new ObjectOutputStream(fos);
			oos.writeObject(date);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	private static void inputObject() {
		try {
			FileInputStream fis = new FileInputStream("E:/abc.date");
			ObjectInputStream ois = new ObjectInputStream(fis);
			Date date = (Date) ois.readObject();
			System.out.println(date);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
